﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using OF.Component.DTO;
using OF.Component.IDAL;
using OF.Utility;

namespace OF.Component.DAL
{
    public class Post:IPost
    {//连接字符串
        public virtual string ConnectionStringKey
        {
            get
            {
                return ConstantUtility.ConnectionEjautobaseKey;
            }
        }
        public IList<PostDetailDto> SearchHotList(scPost condition, out int total)
        {
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetStoredProcCommand("up_Post_SearchHot");

            db.AddInParameter(dbc, "@PageIndex", DbType.Int32, condition.page);
            db.AddInParameter(dbc, "@PageSize", DbType.Int32, condition.rows);
            db.AddOutParameter(dbc, "@OutCount", DbType.Int32, 4);

            DataSet dr = db.ExecuteDataSet(dbc);
            total = (int)db.GetParameterValue(dbc, "@OutCount");
            return SQLServerProvider.CreateList<PostDetailDto>(dr.Tables[0]);
        }

        public IList<PostDetailDto> SearchListByCondition(scPostCondition condition, out int total)
        {
            Database db = DatabaseFactory.CreateDatabase(this.ConnectionStringKey);
            DbCommand dbc = db.GetStoredProcCommand("up_Post_SearchCondition");
            db.AddInParameter(dbc, "@PostType", DbType.Int32, condition.PostType);
            db.AddInParameter(dbc, "@BizTypeID", DbType.Int32, condition.BizTypeID);
            db.AddInParameter(dbc, "@LocationID", DbType.Int32, condition.LocationID);
            db.AddInParameter(dbc, "@GroupID", DbType.Int32, condition.GroupID);
            db.AddInParameter(dbc, "@ProvinceID", DbType.Int32, condition.ProvinceID);
            db.AddInParameter(dbc, "@Content", DbType.String, condition.Content);
            db.AddInParameter(dbc, "@PageIndex", DbType.Int32, condition.page);
            db.AddInParameter(dbc, "@PageSize", DbType.Int32, condition.rows);
            db.AddOutParameter(dbc, "@OutCount", DbType.Int32, 4);

            DataSet dr = db.ExecuteDataSet(dbc);
            total = (int)db.GetParameterValue(dbc, "@OutCount");
            return SQLServerProvider.CreateList<PostDetailDto>(dr.Tables[0]);
        }
    }
}
